<?php

header("Content-Type:text/html;charset=utf-8");

$username = $_POST['username'];
$password = $_POST['password'];

$link = mysqli_connect('localhost','root','root','user');
$res = mysqli_query($link,"SELECT * FROM `userinfo` WHERE `username` = '$username'");

if(mysqli_fetch_assoc($res)){
    if(mysqli_fetch_assoc(mysqli_query($link,"SELECT * FROM `userinfo` WHERE `password` = '$password'"))){
        $arr = array(
            'status'=>1,
            'meta'=>[
                'msg'=>'登录成功!',
                'data'=>$username
            ]
        );
    }else{
        $arr = array(
            'status'=>2,
            'meta'=>[
                'msg'=>'账号或密码错误',
                'data'=>null
            ]
        );
    }
}else{
    $arr = array(
        'status'=>0,
        'meta'=>[
            'msg'=>'账号或密码错误',
            'data'=>null
        ]
    );
}

echo json_encode($arr);
?>